﻿// Copyright (c) Kona Framework Team. All rights reserved.
// For continued development and updates, visit http://www.codeplex.com/kona
// For a copy of the license please vist: http://www.codeplex.com/kona/license
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Kona.Data.Tests.CodeSample.Reports.Queries;
using Kona.Data.Tests.CodeSample.Reports.Queries.Parameters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using AdomdClient = Microsoft.AnalysisServices.AdomdClient;
using Kona.Data;
using System.Xml;
using System.Xml.Linq;

namespace Kona.Data.Tests.CodeSample
{
    /// <summary>
    /// Summary description for AdoMdDataAccess
    /// </summary>
    [TestClass]
    public class AdoMdDataAccess
    {
        private static readonly XNamespace XMLA_NAMESPACE = "urn:schemas-microsoft-com:xml-analysis:mddataset";

        public AdoMdDataAccess()
        {
            //
            // TODO: Add constructor logic here
            //
        }


        [TestMethod]
        public void TransformationWithReader()
        {
            using (AdoMdConnection Connection1 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW Standard Edition"))
            {
                Connection1.Open();
                using (AdoMdCommand Command = new AdoMdCommand())
                {
                    Command.Connection = Connection1;
                    Command.CommandText = "select [Date].[Month of Year].Children  on 0, " +
                                          "[Customer].[Customer Geography].[Country].&[United States].Children on 1 " +
                                          "from [Adventure Works] " +
                                          "where ([Measures].[Customer Count],[Date].[Fiscal Year].&[2004])";
                    XmlReader Reader = Command.ExecuteXmlReader();
                    Reader.ReadToDescendant("Axes", XMLA_NAMESPACE.NamespaceName);
                    System.Xml.XmlReader SubTreeReader = Reader.ReadSubtree();
                    XElement AxesElement = XElement.Load(SubTreeReader);
                    Reader.ReadToFollowing("CellData", XMLA_NAMESPACE.NamespaceName);
                    SubTreeReader = Reader.ReadSubtree();
                    XElement CellDataElement = XElement.Load(SubTreeReader);

                    Assert.IsNotNull(CellDataElement);
                    Assert.IsNotNull(AxesElement);
                }
                Connection1.Close();
            }
        }

        [TestMethod]
        public void GetStronglyTypedResultsFromQuery()
        {
            using (AdoMdConnection Connection1 = new AdoMdConnection("Data Source=localhost;Catalog=Adventure Works DW Standard Edition"))
            {
                Reports.Queries.UsCustomerCountsByStateForFiscalYearQuery Query = 
                    new UsCustomerCountsByStateForFiscalYearQuery(Connection1,new FiscalYear(2004));
            }
        }
    }
}
